<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            ①确定dp数组和下标含义：
            i表示第i级台阶
            dp[i]表示爬到第i级台阶有的方法
            ②确定递推公式
            到当前台阶，每次有两种可能，dp[i]=dp[i-1]+dp[i-2] 
            ③初始化dp数组
            dp[0]=1 dp[1]=1
            ④确定遍历顺序
            因为dp[i]依赖于前两项，所以从左向右遍历
            */
            var climbStairs = function (n) {
                let dp = new Array(n + 1)
                dp[0] = 1
                dp[1] = 1
                for (let i = 2; i <= n; i++) {
                    dp[i] = dp[i - 1] + dp[i - 2]
                }
                return dp[n]
            }
            console.log(climbStairs(3))
        </script>
    </body>
</html>
